package com.guilin.controller;

import com.guilin.common.core.controller.BaseController;
import com.guilin.common.core.domain.AjaxResult;
import com.guilin.common.core.page.TableDataInfo;
import com.guilin.common.utils.poi.ExcelUtil;
import com.guilin.domain.ForumCategory;
import com.guilin.system.service.ForumCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 论坛分类Controller
 *
 * @author xiaoqi
 * @date 2025-06-20
 */
@RestController
@RequestMapping("/admin-management/forumcategory")
public class ForumCategoryController extends BaseController
{
    @Autowired
    private ForumCategoryService forumCategoryService;

    /**
     * 查询论坛分类列表
     */
    //@PreAuthorize("@ss.hasPermi('admin-management:forumcategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ForumCategory forumCategory)
    {
        startPage();
        List<ForumCategory> list = forumCategoryService.selectForumCategoryList(forumCategory);
        return getDataTable(list);
    }

    /**
     * 导出论坛分类列表
     */
    @PreAuthorize("@ss.hasPermi('admin-management:forumcategory:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, ForumCategory forumCategory)
    {
        List<ForumCategory> list = forumCategoryService.selectForumCategoryList(forumCategory);
        ExcelUtil<ForumCategory> util = new ExcelUtil<ForumCategory>(ForumCategory.class);
        util.exportExcel(response, list, "论坛分类数据");
    }

    /**
     * 获取论坛分类详细信息
     */
    //@PreAuthorize("@ss.hasPermi('admin-management:forumcategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(forumCategoryService.selectForumCategoryById(id));
    }

    /**
     * 新增论坛分类
     */
    @PreAuthorize("@ss.hasPermi('admin-management:forumcategory:add')")
    @PostMapping
    public AjaxResult add(@RequestBody ForumCategory forumCategory)
    {
        return toAjax(forumCategoryService.insertForumCategory(forumCategory));
    }

    /**
     * 修改论坛分类
     */
    @PreAuthorize("@ss.hasPermi('admin-management:forumcategory:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody ForumCategory forumCategory)
    {
        return toAjax(forumCategoryService.updateForumCategory(forumCategory));
    }

    /**
     * 删除论坛分类
     */
    @PreAuthorize("@ss.hasPermi('admin-management:forumcategory:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(forumCategoryService.deleteForumCategoryByIds(ids));
    }
}
